package com.mxx.springaction;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class BraveKnight implements Knight, BeanNameAware, BeanFactoryAware, InitializingBean, ApplicationContextAware, DisposableBean {

    private Quest quest;

    public BraveKnight() {
        System.out.println("1.实例化。。。。。。。。。。");
    }

    public void init() {
        System.out.println("7.init。。。。。。。。。。");
    }

    @Override
    public void embarkOnQequest() {
        System.out.println("8.5--------------embarkOnQequest。。。。。。。。");
        quest.embark();
    }


    public void setQuest(Quest quest) {
        System.out.println("2.注入属性...........");
        this.quest = quest;
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("3.实现了beanNameAware接口" + name + "......");
    }

    /**
     * 所有的bean在beanDefinitionMap中存储
     *
     * @param beanFactory
     * @throws BeansException
     */
    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("4.实现了BeanFactoryAware接口" + beanFactory.getBean("knight").toString());
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("5.实现applicationContext接口" + applicationContext.getBean("knight").toString());
    }


    @Override
    public void destroy() throws Exception {
        System.out.println("9.destroy...........");
    }


    public void myDestroy() throws Exception {
        System.out.println("9.mydestroy...........");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("7.afterPropertiesSet");
    }
}
